/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package co.infinum.goldfinger;

/**
 * A data class exception that holds the results of an authentication request failure.
 * 认证结果
 *
 * @since 2021-06-25
 */
public class AuthenticationResult {
    public enum Status {SUCCESS, NONFATAL_FAILURE, FATAL_FAILURE}

    /**
     * The result of the authenticate call.
     * <p>
     * If the status is NONFATAL_FAILURE, the fingerprint sensor is still running, and more
     * events will be emitted. Other statuses are terminal events, and the fingerprint sensor will
     * be stopped by the time they are emitted.
     */
    public final Status status;

    /**
     * The general reason for the failure.
     * <p>
     * Will be null if the authentication succeeded, and non-null otherwise.
     */
    public final int failureReason;

    /**
     * An informative string given by the underlying fingerprint sdk that can be displayed in the ui.
     * <p>
     * Will be null if the authentication succeeded, and non-null otherwise.
     * <p>
     * The will be localized to the current locale.
     */
    public final CharSequence errorMessage;

    /**
     * The {@link } of the module that is currently active.
     * <p>
     * This is useful to know the meaning of the error code.
     * 这有助于了解错误代码的含义
     */
    public final int fromModule;

    /**
     * The specific error code returned by the module's underlying sdk.
     * <p>
     * Check the constants defined in the module for possible values and their meanings.
     */
    public final int errorCode;

    /**
     * 验证结果
     *
     * @param status        状态
     * @param failureReason 错误原因
     * @param errorMessage  错误提示
     * @param fromModule    验证类型
     * @param errorCode     错误code
     */
    public AuthenticationResult(Status status, int failureReason,
                                CharSequence errorMessage, int fromModule, int errorCode) {
        this.status = status;
        this.failureReason = failureReason;
        this.errorMessage = errorMessage;
        this.fromModule = fromModule;
        this.errorCode = errorCode;
    }
}
